package com.iengine.services.api.command.homecontrol;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import com.iengine.services.api.utils.Constant;

public class CommandAirCondition extends AbstractTxtHomeControlApiCommand {
	
	public static final String FIELD_TEMP_VERB = "TempVerb";
	public static final String FIELD_ATEMP = "ATemp";
	public static final String FIELD_BTEMP = "BTemp";
	public static final String FIELD_WIND_VERB = "WindVerb";
	public static final String FIELD_WIND_LEVEL = "WindLevel";
	/**
	 * 制冷##0#_#制热##1#_#除湿##2#_#自动##11#_#
	 */
	public static final String FIELD_MODE = "Mode";
	public static final String FIELD_WIND_MODE = "WindMode";
	public static final String FIELD_TIME_HOUR = "TimeHour";
	public static final String FIELD_TIME_MIN = "TimeMin";
	public static final String FIELD_TIME_OP = "TimeOP";

	private final static Map<String,Map<String,String>> convertData = new HashMap<String,Map<String,String>>();
	static{
		//TODO暂时处理
		//温度 0：设置 1：调高  2：调低
		Map<String,String> tempMap = new HashMap<String,String>();
		tempMap.put("0", "设置");
		tempMap.put("1", "调高");
		tempMap.put("2", "调低");
		convertData.put(FIELD_TEMP_VERB, tempMap);
		//风速 1：调高  2：调低
		tempMap = new HashMap<String,String>();
		tempMap.put("1", "调高");
		tempMap.put("2", "调低");
		convertData.put(FIELD_WIND_VERB, tempMap);
		//风级别 0：高风  1：中风  2：低风
		tempMap = new HashMap<String,String>();
		tempMap.put("0", "高风");
		tempMap.put("1", "中风");
		tempMap.put("2", "低风");
		convertData.put(FIELD_WIND_LEVEL, tempMap);
		//风模式0：扫风 1：送风 2：左右扫风  3：上下扫风
		tempMap = new HashMap<String,String>();
		tempMap.put("0", "扫风");
		tempMap.put("1", "送风");
		tempMap.put("2", "左右扫风");
		tempMap.put("3", "上下扫风");
		convertData.put(FIELD_WIND_MODE, tempMap);
		//模式0：制冷##0#_#制热##1#_#除湿##2#_#自动##12#_#
		tempMap = new HashMap<String,String>();
		tempMap.put("0", "制冷");
		tempMap.put("1", "制热");
		tempMap.put("2", "除湿");
		tempMap.put("11", "自动");
		tempMap.put("13", "左右摆风");
		tempMap.put("12", "上下摆风");
		tempMap.put("3", "加湿");
		tempMap.put("4", "抽湿");
		tempMap.put("20", "经济");
		tempMap.put("32", "感人");
		tempMap.put("43", "切换");
		convertData.put(FIELD_MODE, tempMap);
		
	
	}
	
	protected Map formatArgs(Map map, Map nlpParams) {
		return process(map, nlpParams);
	}
	
	//获取参数
	@SuppressWarnings("unchecked")
	public Map<String, Object> process(Map<String,Object> map, Map nlpParams){  	
		String tempVerb = getValue(nlpParams.get(FIELD_TEMP_VERB),"");
		if(null != convertData.get(FIELD_TEMP_VERB).get(tempVerb)){
			nlpParams.put(FIELD_TEMP_VERB, convertData.get(FIELD_TEMP_VERB).get(tempVerb));
		}
		String windVerb = getValue(nlpParams.get(FIELD_WIND_VERB),"");
		if(null != convertData.get(FIELD_WIND_VERB).get(windVerb)){
			nlpParams.put(FIELD_WIND_VERB, convertData.get(FIELD_WIND_VERB).get(windVerb));
		}
		
		String windLevel = getValue(nlpParams.get(FIELD_WIND_LEVEL),"");
		if(null != convertData.get(FIELD_WIND_LEVEL).get(windLevel)){
			nlpParams.put(FIELD_WIND_LEVEL, convertData.get(FIELD_WIND_LEVEL).get(windLevel));
		}
		
		String windMode = getValue(nlpParams.get(FIELD_WIND_MODE),"");
		if(null != convertData.get(FIELD_WIND_MODE).get(windMode)){
			nlpParams.put(FIELD_WIND_MODE, convertData.get(FIELD_WIND_MODE).get(windMode));
		}
	
		String mode = getValue(nlpParams.get(FIELD_MODE),"");
		if(null != convertData.get(FIELD_MODE).get(mode)){
			nlpParams.put(FIELD_MODE, convertData.get(FIELD_MODE).get(mode));	    
		}
		map.put(Constant.FIELD_NLPPARAMS, nlpParams);
		//return temp;
		return map;
	}

}
